package media

import (
	"beesoft.ink/application/media/app/model/media"
	"context"
	"errors"
	"fmt"
)

var Recognition recognition

type recognition struct{}

func (r *recognition) Whisper1(ctx context.Context, req *media.AudioRecognitionRequest) (*media.AudioRecognitionResponse, error) {
	response := new(media.AudioRecognitionResponse)

	client := openai.NewClient(Org.Openai.Apikey)
	res, err := client.CreateTranscription(ctx, openai.AudioRequest{
		Model:    openai.Whisper1,
		FilePath: req.Path,
	})
	if err != nil {
		return response, errors.New(fmt.Sprintf("Transcription error: %v\n", err))
	}

	response.Content = res.Text

	return response, nil
}
